<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="0正常 1删除" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isDelete">
              <a-input-number v-model="model.isDelete" placeholder="请输入0正常 1删除" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderNo">
              <a-input v-model="model.orderNo" placeholder="请输入订单编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="用户id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userId">
              <a-input v-model="model.userId" placeholder="请输入用户id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单总金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="totalOrderAmount">
              <a-input-number v-model="model.totalOrderAmount" placeholder="请输入订单总金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-input v-model="model.remark" placeholder="请输入备注"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="支付状态;1未付款 2已支付 3已退款 4取消订单 5关闭订单" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderStatus">
              <a-input-number v-model="model.orderStatus" placeholder="请输入支付状态;1未付款 2已支付 3已退款 4取消订单 5关闭订单" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <a-input v-model="model.name" placeholder="请输入姓名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="手机号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="phone">
              <a-input v-model="model.phone" placeholder="请输入手机号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="省code" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="provinceCode">
              <a-input v-model="model.provinceCode" placeholder="请输入省code"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="省名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="provinceName">
              <a-input v-model="model.provinceName" placeholder="请输入省名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="市code" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cityCode">
              <a-input v-model="model.cityCode" placeholder="请输入市code"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="市名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cityName">
              <a-input v-model="model.cityName" placeholder="请输入市名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="区code" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="areaCode">
              <a-input v-model="model.areaCode" placeholder="请输入区code"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="区名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="areaName">
              <a-input v-model="model.areaName" placeholder="请输入区名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="具体地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="address">
              <a-input v-model="model.address" placeholder="请输入具体地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="1物流 2自提" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isSelfLifting">
              <a-input-number v-model="model.isSelfLifting" placeholder="请输入1物流 2自提" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="1待收货 2已经收货 0未发货" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isDeliver">
              <a-input-number v-model="model.isDeliver" placeholder="请输入1待收货 2已经收货 0未发货" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="运费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="freight">
              <a-input-number v-model="model.freight" placeholder="请输入运费" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="0 无退款 1退款中 3已退款 4退款失败" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="refundStatus">
              <a-input-number v-model="model.refundStatus" placeholder="请输入0 无退款 1退款中 3已退款 4退款失败" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="退款单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="refundNo">
              <a-input v-model="model.refundNo" placeholder="请输入退款单号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="支付单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="payNo">
              <a-input v-model="model.payNo" placeholder="请输入支付单号"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'GalleryOrderForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           isDelete: [
              { required: true, message: '请输入0正常 1删除!'},
           ],
           orderNo: [
              { required: true, message: '请输入订单编号!'},
           ],
           userId: [
              { required: true, message: '请输入用户id!'},
           ],
           totalOrderAmount: [
              { required: true, message: '请输入订单总金额!'},
           ],
           orderStatus: [
              { required: true, message: '请输入支付状态;1未付款 2已支付 3已退款 4取消订单 5关闭订单!'},
           ],
           name: [
              { required: true, message: '请输入姓名!'},
           ],
           phone: [
              { required: true, message: '请输入手机号!'},
           ],
           provinceCode: [
              { required: true, message: '请输入省code!'},
           ],
           provinceName: [
              { required: true, message: '请输入省名称!'},
           ],
           cityCode: [
              { required: true, message: '请输入市code!'},
           ],
           cityName: [
              { required: true, message: '请输入市名称!'},
           ],
           areaCode: [
              { required: true, message: '请输入区code!'},
           ],
           areaName: [
              { required: true, message: '请输入区名称!'},
           ],
           address: [
              { required: true, message: '请输入具体地址!'},
           ],
           isSelfLifting: [
              { required: true, message: '请输入1物流 2自提!'},
           ],
           isDeliver: [
              { required: true, message: '请输入1待收货 2已经收货 0未发货!'},
           ],
           freight: [
              { required: true, message: '请输入运费!'},
           ],
           refundStatus: [
              { required: true, message: '请输入0 无退款 1退款中 3已退款 4退款失败!'},
           ],
           refundNo: [
              { required: true, message: '请输入退款单号!'},
           ],
           payNo: [
              { required: true, message: '请输入支付单号!'},
           ],
        },
        url: {
          add: "/gallery/galleryOrder/add",
          edit: "/gallery/galleryOrder/edit",
          queryById: "/gallery/galleryOrder/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>